var service = angular.module("service", []);
service.service("noteListService",function ($http,$q) {
    this.getNoteList = function (param) {
        var defer = $q.defer();
        var getPath = JSON.parse(localStorage.getItem("getPath"));
        var url = getPath.url+getPath.name+"/app/getBookNoteByPage";
        var promise = $http({
            url: url,
            method: "POST",
            data:param,
            headers:{'Content-Type':'application/x-www-form-urlencoded'}
        });
        promise.then(this.onSuccess,this.onError);
        defer.resolve(promise);
        return defer.promise;
    }
    //成功返回
    this.onSuccess = function(result){
        var defer = $q.defer();
        if(result.status==200){
            defer.resolve(result);
        }else{
            defer.reject("没有更多笔记了");
        }
        return defer.promise;
    }
    //失败
    this.onError = function(){
        var defer = $q.defer();
        defer.reject("获取笔记列表失败！");
        return defer.promise;
    }
});